package com.ccloud.blog.modules.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccloud.blog.modules.blog.domain.Blog;
import com.ccloud.blog.modules.blog.enums.BlogEnum;
import com.ccloud.blog.modules.blog.mapper.BlogMapper;
import com.ccloud.blog.modules.blog.service.IBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chentailai
 * @since 2019-09-05
 */
@Service
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IBlogService {


    @Override
    public List<Map<String, Object>> getBlogList(Page<Map<String, Object>> page, Blog blog, String orderBy) {
        List<Map<String, Object>> list = this.baseMapper.getBlogList(page, blog, orderBy);
        return list;
    }

    @Override
    public List<Map<String, Object>> getBlogsByBlogTypeId(Integer blogTypeId) {
        return this.baseMapper.getBlogsByBlogTypeId(blogTypeId);
    }

    @Override
    public List<Map<String, Object>> getRecommendedArticle(Blog blog) {
        return this.baseMapper.getRecommendedArticle(blog);
    }

    @Override
    public boolean removeByBlogTypeId(Integer blogTypeId) {
        QueryWrapper<Blog> wrapper = new QueryWrapper<>();
        wrapper.eq("blogTypeId", blogTypeId);
        return remove(wrapper);
    }

    @Override
    public List<Blog> getAllPublishedBlogs() {
        QueryWrapper<Blog> wrapper = new QueryWrapper<>();
        wrapper.eq("isPublished", BlogEnum.IS_PUBLISHED.getCode());
        return list(wrapper);
    }
}
